# name : Check whether dataset is empty
# key : dataset.empty.check
# contributor: Shuguang Sun
# --
%macro dtempty_check(dsn);
  %global _dsnr;
  %let _dsnr = 0;

  %let dsid=%sysfunc(open(&dsn));

  %if &dsid ne 0 %then %do;
    %let cnt=%sysfunc(attrn(&dsid,nlobs));
    %let rc=%sysfunc(close(&dsid));
    %if &cnt ne 0 %then %do;
     proc print data=&dsn;
      title "This is data from data set &dsn";
     run;
    %end;
    %else %do;
     data _null_;
      title;
      file print;
      put _page_;
      put "Data set &dsn is empty.";
     run;
    %end;
  %end;
  %else %put &dsn cannot be open.;

  %mend dtempty_check;